{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}

{block name="content"}
<div class="tablesWrap">
    {include file="./Public_forms.html"}
    <!-- end tables-searchbox -->
    <table class="wxtables">
        <colgroup>
        <col width="5%">
        <col width="8%">
        <col width="8%">
        <col width="8%">
        <col width="8%">
        <col width="12%">
        <col width="10%">
        <col width="9%">
        <col width="12%">
        <col width="15%">
        </colgroup>
        <thead>
            <tr>
                <td>选择</td>
                <td>订单编号</td>
                <td>下单时间</td>
                <td>收货人</td>
                <td>订单金额</td>
                <td>付款方式</td>
                <td>配送方式</td>
                <td>订单实收款</td>
                <td>订单状态</td>
                <td>操作</td>
            </tr>
        </thead>
        {foreach from=$order_list item=order_info}
        <tbody class="combo-tbody">  
        	<tr>  
				<td><input type="checkbox" class="checkbox" name="a[]" value="{$order_info.order_id}"></td>
				<td><span class="t-le">{$order_info.order_sn}</span></td>
				<td><span class="t-le">{$order_info.addtime|date_format:"%Y-%m-%d %H:%M:%S"}</span></td>
                <td>{$order_info.consignee}</td>  
                <td>
                	<span>￥</span>  
					<span>{$order_info.total_amount + $order_info.express_fee}</span> 
                </td>  
                <td>{if $order_info.payway}{$order_info.payway}{else}--{/if}</td>  
                <td>{if $order_info.express_company_name}{$order_info.express_company_name}{else}--{/if}</td>  
                <td>
                	<span>￥</span>  
					<!--<span>{$order_info.total_amount + $order_info.express_fee}</span>-->
					<span>{$order_info.pay_amount}</span>
                </td>  
				<td>{$order_info.order_status_name}</td> 
                <td>  
					<a href="/AcpOrder/order_detail/order_id/{$order_info.order_id}/redirect/{$redirect}" class="btn" title="查看">查看</a>   
                    <!--<a href="/AcpOrder/edit_order/order_id/{$order_info.order_id}/redirect/{$redirect}" class="btn" title="修改">编辑</a> 
						<a href="javascript:offline_pay({$order_info.order_id}, 0);" class="btn" title="已线下收款">已线下收款</a>
						<a href="javascript:confirm_refund_delivered({$order_info.order_id});" class="btn" title="确认收货">确认收货</a>-->
                        {if $opt == 'REFUNDED'}
						<a href="javascript:;" class="btn" title="删除" onclick="delete_order({$order_info.order_id})">删除</a>  
                        {/if}
                        {if $opt == 'PAYED_FINISH'}
						<a href="javascript:;" class="btn" title="发货" onclick="deliver_order({$order_info.order_id})">发货</a>  
                        {/if}
                        {if $opt == 'PRE_REFUND'}
						<a href="javascript:;" class="btn" title="退款" onclick="GroupRefundChange({$order_info.order_id})">退款</a>   
                        {/if}
                </td>  
            </tr>
        </tbody> 
		{foreachelse}
        <tbody>       
			<tr>
				<td colspan="7">
					没有符合条件的记录
				</td>
			<tr>
        </tbody>
		{/foreach} 
    </table>  
    <!-- end wxtables -->  
    <div class="tables-btmctrl clearfix">  
        <div class="fl">  
            <a href="javascript:;" class="btn btn-blue" onclick="Select()">全选</a>  
            <a href="javascript:;" class="btn btn-blue" onclick="Cancel()">取消</a>  
            <a href="javascript:;" class="btn btn-blue" onclick="batch_delete()">关闭</a>  
			{if $order_info.order_status == OrderModel::PAYED}
				<!--<a href="javascript:;" class="btn btn-blue" onclick="print_packing_list();">批量打印配货单</a>  
				<a href="javascript:;" class="btn btn-blue" id="print_selected">批量打印快递单</a>  
				<a href="javascript:;" onclick="print_invoice()" class="btn btn-blue">批量打印发货单</a>  
				<a href="javascript:;" onclick="batch_deliver()" class="btn btn-blue">批量发货</a>-->
			{/if}
        </div>  
        <div class="fr">  
            <div class="paginate">
				{$show}
            </div>  
            <!-- end paginate -->  
        </div>  
    </div>  
    <!-- end tables-btmctrl -->  
</div>  

<object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
	<embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
</object>

<div id="globalPop"></div>
<!-- end tablesWrap -->   
{/block} 

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__JS__/acp/AcpOrder/order.js?version={$version}"></script>
<script src="__JS__/acp/AcpOrder/get_pre_stockup_order_list.js?version={$version}"></script>
<script src="__JS__/acp/AcpOrder/get_pre_deliver_order_list.js?version={$version}"></script>
<script src="__JS__/lodop/LodopFuncs.js?version={$version}"></script>
<script src="__JS__/acp/AcpOrder/print_shipping.js?version={$version}"></script>
{literal} 
<script>
//全选
function Select(){
    var sel=document.getElementsByName("a[]");
    for(var i=0;i<sel.length;i++){
        sel[i].checked=true;
    }
}
//取消全选
function Cancel(){
    var sel=document.getElementsByName("a[]");
    for(var i=0;i<sel.length;i++){
        sel[i].checked=false;
    }
}

function confirm_refund_delivered(order_id)
{
	var html='';

	var html='<form id="deliver_form">' + 
			'<div class="formitems inline">'+
				'<label class="fi-name"><span class="colorRed">*</span>退款金额：</label>'+ 
				'<div class="form-controls">'+
					'<input name="freight_name" id="freight_name"><span class="fi-help-text"> </span>'+
				'</div>' + 
			'</div>'+
		'</form>';
	
	$.jPops.custom({
		title:"确认收货并退款",  
		content:html,
		okBtnTxt:"确定",  
		cancelBtnTxt:"取消",  
		callback:function(r)
		{
			if(r)
			{
			    var refund_total  = $('#freight_name').val();

				$.validator.setDefaults(
				{
					//表单验证通过后的处理，异步提交表单
					submitHandler: function()
					{
						$.post('/AcpOrder/confirm_refund_deliving',{"order_id":order_id, "refund_total":refund_total},function(data)
						{
							if (data == 'success')
							{
								alert('恭喜您，操作成功');
								location.reload();
							}
							else
							{
								alert('对不起，操作失败');
							}
						})
						acp.batchDeliverFormStatus = true;
					}
				});
			
				//表单验证规则
				$("#deliver_form").validate(
				{
					rules: 
					{
						freight_name: 
						{
							required: true,
							digits: true
						},
					},
					messages: 
					{
						freight_name: 
						{
							required: "对不起，请填写退款金额",
							digits: "金额请填写数字!"
						},
					},
					errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
					success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
				});

				//模拟提交表单
				$("#deliver_form").submit();
				return acp.batchDeliverFormStatus;
			}
			else
			{
				return true;  
			}
		}
	});
}

function deliver_order(order_id)
{
	var html='';

	var html='<form id="deliver_form">' + 
			'<div class="formitems inline">'+
				'<label class="fi-name"><span class="colorRed">*</span>快递公司：</label>'+ 
				'<div class="form-controls">'+
				'<select class="small" name="express_company_id" id="express_company_id">'+
                {/literal}
					'<option value="">--选择物流公司--</option>'+
					{foreach from=$express_company_list item=express_company_info}
						'<option value="{$express_company_info.shipping_company_id}">{$express_company_info.shipping_company_name}</option>'+
					{/foreach}
                {literal}
				'</select><span class="fi-help-text"> </span>'+
				'</div>' + 
			'</div>'+
			'<div class="formitems inline">'+
				'<label class="fi-name"><span class="colorRed">*</span>快递单号：</label>'+ 
				'<div class="form-controls">'+
					'<input name="express_number" id="express_number"><span class="fi-help-text"> </span>'+
				'</div>' + 
                '<input type="hidden" name="order_id" value="'+order_id+'">'+
			'</div>'+
		'</form>';
	
	$.jPops.custom({
		title:"发货",  
		content:html,
		okBtnTxt:"确定",  
		cancelBtnTxt:"取消",  
		callback:function(r)
		{
			if(r)
			{

				$.validator.setDefaults(
				{
					//表单验证通过后的处理，异步提交表单
					submitHandler: function()
					{
						$.post('/AcpOrder/deliver_order',$('#deliver_form').serialize(),function(data)
						{
							if (data == 'success')
							{
								alert('恭喜您，操作成功');
								location.reload();
							}
							else
							{
								alert('对不起，操作失败');
							}
						})
						acp.batchDeliverFormStatus = true;
					}
				});
			
				//表单验证规则
				$("#deliver_form").validate(
				{
					rules: 
					{
						express_company_id: 
						{
							required: true,
							digits: true
						},
						express_number: 
						{
							required: true,
							digits: true
						},
					},
					messages: 
					{
						express_company_id: 
						{
							required: "对不起，请选择快递公司",
						},
						express_number: 
						{
							required: "对不起，请填写快递单号",
						},
					},
					errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
					success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
				});

				//模拟提交表单
				$("#deliver_form").submit();
				return acp.batchDeliverFormStatus;
			}
			else
			{
				return true;  
			}
		}
	});
}

function GroupRefundChange(id)
{
console.log(id);
	$.jPops.confirm(
	{
		 title:"提示",
		 content:"您确定要退款吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 $.post('/AcpOrderAjax/group_refund_change', {"id":id}, function(data, textStatus) 
				 {
					if (data == 'success')
					{
						alert('恭喜您，已退款成功！');
						location.reload();
					}
					else
					{
						alert('对不起，退款失败！');
					}
				});
			 }  
			 else{  
				 // console.log("我是confirm的回调,false");  
			 }  
			 return true;  
		 }
	});
}
</script>
{/literal} 
{/block} 

{block name="css"}
<link rel="stylesheet" href="/Public/Css/acp/AcpOrder/get_pre_pay_order_list.css" type="text/css" />
{literal}
<style>
#jpops .fi-name{width:80px;}
#jpops .form-controls{margin-left:100px;}
</style>
{/literal}
{/block} 
